home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / java / twolists / frame1.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-02-07  |  4.7 KB  |  156 lines

  1. import java.awt.Component;
  2. import java.awt.Container;
  3. import java.awt.Event;
  4. import java.awt.FileDialog;
  5. import java.awt.Frame;
  6. import java.awt.Label;
  7. import java.awt.LayoutManager;
  8. import java.awt.List;
  9. import java.awt.Menu;
  10. import java.awt.MenuBar;
  11. import java.awt.MenuItem;
  12.  
  13. public class Frame1 extends Frame {
  14.    FileDialog OpenFileDialog;
  15.    List StockList;
  16.    List BasketList;
  17.    Label label1;
  18.    Label label2;
  19.    Label label3;
  20.    Label label4;
  21.    MenuBar mainMenuBar;
  22.    Menu menu1;
  23.    Menu menu2;
  24.    Menu menu3;
  25.  
  26.    void BasketList_DblClick(Event event) {
  27.       this.StockList.addItem(this.BasketList.getSelectedItem());
  28.       this.BasketList.delItem(this.BasketList.getSelectedIndex());
  29.    }
  30.  
  31.    void StockList_DblClick(Event event) {
  32.       this.BasketList.addItem(this.StockList.getSelectedItem());
  33.       this.StockList.delItem(this.StockList.getSelectedIndex());
  34.    }
  35.  
  36.    void Open_Action(Event event) {
  37.       this.OpenFileDialog.show();
  38.    }
  39.  
  40.    void About_Action(Event event) {
  41.       (new AboutDialog(this, "About...", false)).show();
  42.    }
  43.  
  44.    void Exit_Action(Event event) {
  45.       (new QuitDialog(this, "Quit the Application?", false)).show();
  46.    }
  47.  
  48.    public Frame1() {
  49.       ((Container)this).setLayout((LayoutManager)null);
  50.       ((Frame)this).addNotify();
  51.       ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 457, ((Container)this).insets().top + ((Container)this).insets().bottom + 322);
  52.       this.OpenFileDialog = new FileDialog(this, "Open", 0);
  53.       this.StockList = new List(0, false);
  54.       ((Container)this).add(this.StockList);
  55.       this.StockList.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 45, 201, 225);
  56.       this.BasketList = new List(0, false);
  57.       ((Container)this).add(this.BasketList);
  58.       this.BasketList.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 45, 201, 225);
  59.       this.label1 = new Label("ITEMS IN STOCK");
  60.       this.label1.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 15, 196, 15);
  61.       ((Container)this).add(this.label1);
  62.       this.label2 = new Label("ITEMS IN YOUR BASKET");
  63.       this.label2.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 15, 203, 15);
  64.       ((Container)this).add(this.label2);
  65.       this.label3 = new Label("DOUBLE-CLICK TO BUY");
  66.       this.label3.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 278, 203, 22);
  67.       ((Container)this).add(this.label3);
  68.       this.label4 = new Label("DOUBLE-CLICK TO PUT BACK");
  69.       this.label4.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 278, 203, 24);
  70.       ((Container)this).add(this.label4);
  71.       ((Frame)this).setTitle("A Basic Application");
  72.       this.mainMenuBar = new MenuBar();
  73.       this.menu1 = new Menu("File");
  74.       this.menu1.add("Open...");
  75.       this.menu1.add("Save");
  76.       this.menu1.add("Save As...");
  77.       this.menu1.addSeparator();
  78.       this.menu1.add("Exit");
  79.       this.mainMenuBar.add(this.menu1);
  80.       this.menu2 = new Menu("Edit");
  81.       this.menu2.add("Cut");
  82.       this.menu2.add("Copy");
  83.       this.menu2.add("Paste");
  84.       this.mainMenuBar.add(this.menu2);
  85.       this.menu3 = new Menu("Help");
  86.       this.menu3.add("About");
  87.       this.mainMenuBar.add(this.menu3);
  88.       ((Frame)this).setMenuBar(this.mainMenuBar);
  89.    }
  90.  
  91.    public Frame1(String title) {
  92.       this();
  93.       ((Frame)this).setTitle(title);
  94.    }
  95.  
  96.    public synchronized void show() {
  97.       ((Component)this).move(50, 50);
  98.       super.show();
  99.       this.StockList.addItem("Tin of Schpamm");
  100.       this.StockList.addItem("Pot of Schnoodles");
  101.       this.StockList.addItem("Jug of Hare");
  102.       this.StockList.addItem("Kettle of Fish");
  103.       this.StockList.addItem("Bombay Duck");
  104.       this.StockList.addItem("Duck-billed platypus");
  105.       this.StockList.addItem("Can of worms");
  106.       this.StockList.addItem("Hair of the dog");
  107.       this.StockList.addItem("Dog's bone");
  108.       this.StockList.addItem("PC Plus");
  109.    }
  110.  
  111.    public boolean handleEvent(Event event) {
  112.       if (event.id == 201) {
  113.          ((Component)this).hide();
  114.          ((Frame)this).dispose();
  115.          System.exit(0);
  116.          return true;
  117.       } else {
  118.          if (event.target == this.StockList && event.id == 1001) {
  119.             this.StockList_DblClick(event);
  120.          }
  121.  
  122.          if (event.target == this.BasketList && event.id == 1001) {
  123.             this.BasketList_DblClick(event);
  124.          }
  125.  
  126.          return super.handleEvent(event);
  127.       }
  128.    }
  129.  
  130.    public boolean action(Event event, Object arg) {
  131.       if (event.target instanceof MenuItem) {
  132.          String label = (String)arg;
  133.          if (label.equalsIgnoreCase("Open...")) {
  134.             this.Open_Action(event);
  135.             return true;
  136.          }
  137.  
  138.          if (label.equalsIgnoreCase("About")) {
  139.             this.About_Action(event);
  140.             return true;
  141.          }
  142.  
  143.          if (label.equalsIgnoreCase("Exit")) {
  144.             this.Exit_Action(event);
  145.             return true;
  146.          }
  147.       }
  148.  
  149.       return super.action(event, arg);
  150.    }
  151.  
  152.    public static void main(String[] args) {
  153.       (new Frame1()).show();
  154.    }
  155. }
  156.